local quanya = fk.CreateSkill {
  name = "th_quanya",
  max_turn_use_time = 1,
}

quanya:addEffect(fk.CardUsing, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(quanya.name) and target and target:inMyAttackRange(player) and data.card then
      return data.responseToEvent and data.responseToEvent.from and data.responseToEvent.from == player
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = quanya.name,
      prompt = "#th_quanya-invoke:" .. target.id .. "::" .. data.card:toLogString()
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToDiscard(target, {
      min_num = 1,
      max_num = 1,
      include_equip = false,
      skill_name = quanya.name,
      cancelable = true, 
      prompt = "#th_quanya-put::" .. player.id .. ":" .. data.card:toLogString()
    })
    if #cards > 0 then
      room:setPlayerMark(player, "@@th_quanya-turn", 1)
    else
      data.toCard = nil
      data:removeAllTargets()
    end
  end
}, { check_skill_limit = true })
quanya:addEffect(fk.TargetSpecified, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(quanya.name) and target and target:inMyAttackRange(player) and data.card then
      return data.firstTarget and table.contains(data:getAllTargets(), player)
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = quanya.name,
      prompt = "#th_quanya-invoke:" .. target.id .. "::" .. data.card:toLogString()
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToDiscard(target, {
      min_num = 1,
      max_num = 1,
      include_equip = false,
      skill_name = quanya.name,
      cancelable = true, 
      prompt = "#th_quanya-put::" .. player.id .. ":" .. data.card:toLogString()
    })
    if #cards > 0 then
      room:setPlayerMark(player, "@@th_quanya-turn", 1)
    else
      data:setNullified(data:getAllTargets())
    end
  end
}, { check_skill_limit = true })

quanya:addEffect(fk.TurnEnd, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return not player.dead and player:getMark("@@th_quanya-turn") ~= 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@th_quanya-turn", 0)
    local use = room:askToUseCard(player, {
      skill_name = quanya.name,
      pattern = "slash",
      prompt = "#th_quanya-use",
      cancelable = true,
      extra_data = { bypass_times = true }
    })
    if use then
      event:setCostData(self, use)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self)
    room:useCard(use)
  end,
})

Fk:loadTranslationTable{
  ["th_quanya"] = "犬牙",
  [":th_quanya"] = "每回合限一次，攻击范围含有你的角色使用牌指定你为目标后，或使用牌响应你的牌时，你可以令其选择一项：1.弃置一张手牌，本回合结束时你可以使用【杀】；2.此牌无效。",

  ["#th_quanya-invoke"] = "犬牙：你可以令 %src 弃置一张手牌或令 %arg 无效",
  ["#th_quanya-put"] = "犬牙：你需弃置一张手牌，否则 %arg 无效",
  ["#th_quanya-use"] = "犬牙：你可以使用一张【杀】",

  ["@@th_quanya-turn"] = "犬牙",
}

return quanya